#include "common.h"

int next(int n)
{
	int ret = 0;
	while (n != 0)
	{
		int t = n % 10;
		ret += t * t;
		n /= 10;
	}
	return ret;
}

bool isHappy(int n)
{
	map<int, int> _map;
	while (1)
	{
		if (n == 1)
			return true;
		else
		{
			_map[n]++;
			if (_map[n] == 2)
				return false;
		}
		n = next(n);
	}
}